/*
 * @Descripttion:
 * @version:
 * @Author: cpy
 * @Date: 2023-10-11 16:10:00
 */
#ifndef __SPI_H
#define __SPI_H
#include "sys.h"

#define SW_SPI 1
//***PC3-SPI2_SDO   PC2-SPI2_SIN   PB10-SPI2_SCK  PC13-SPI2_PCS1_BAT  PC14-SPI2_PCS2_LINK***//
#ifdef SW_SPI
#define SPI_WP_PIN GPIO_Pin_14
#define SPI_WP_PORT GPIOC

#define SPI_CS_PIN GPIO_Pin_13
#define SPI_CS_PORT GPIOC

#define SPI_CLK_PIN GPIO_Pin_10
#define SPI_CLK_PORT GPIOB

#define SPI_MOSI_PIN GPIO_Pin_3
#define SPI_MOSI_PORT GPIOC

#define SPI_MISO_PIN GPIO_Pin_2
#define SPI_MISO_PORT GPIOC

#define SPI_BASE SPI2

#define SPI_BAT_CS_LOW() GPIO_ResetBits(SPI_CS_PORT, SPI_CS_PIN) /* Select SPI MEM1: ChipSelect pin low  */
#define SPI_BAT_CS_HIGH() GPIO_SetBits(SPI_CS_PORT, SPI_CS_PIN)  /* Deselect SPI MEM1: ChipSelect pin high */

#define SPI_LINK_CS_LOW() GPIO_ResetBits(SPI_WP_PORT, SPI_WP_PIN) // PC4
#define SPI_LINK_CS_HIGH() GPIO_SetBits(SPI_WP_PORT, SPI_WP_PIN)  // PC4
#endif

void SPI1_Init(void);
void SPI1_SetSpeed(u8 SPI_BaudRatePrescaler);
u8 SPI1_ReadByte(u8 *readdata);
u8 SPI1_SendByte(u8 TxData);
u8 Test_Spi_Send(void);

void SPI2_Init(void);
void SPI2_SetSpeed(u8 SPI_BaudRatePrescaler);
u8 SPI2_ReadByte(u8 *readdata);
u8 SPI2_SendByte(u8 TxData);
u8 Test_Spi2_Send(void);
#endif
